home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / shadow-9.tar / shadow-9 / shadow-960129 / fields.c < prev    next >
C/C++ Source or Header  |  1995-12-17  |  3KB  |  95 lines

  1. /*
  2.  * Copyright 1990, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by John F. Haugh, II
  16.  *      and other contributors.
  17.  * 4. Neither the name of John F. Haugh, II nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY JOHN HAUGH AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL JOHN HAUGH OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #include <ctype.h>
  35. #include <string.h>
  36. #include <stdio.h>
  37.  
  38. #ifndef    lint
  39. static char rcsid[] = "$Id: fields.c,v 1.1 1995/12/16 01:15:45 marekm Exp $";
  40. #endif
  41.  
  42. /*
  43.  * valid_field - insure that a field contains all legal characters
  44.  *
  45.  * The supplied field is scanned for non-printing and other illegal
  46.  * characters.  If any illegal characters are found, valid_field
  47.  * returns -1.  Zero is returned for success.
  48.  */
  49.  
  50. int
  51. valid_field (field, illegal)
  52. char    *field;
  53. char    *illegal;
  54. {
  55.     char    *cp;
  56.  
  57.     for (cp = field;*cp && isprint (*cp) && ! strchr (illegal, *cp);cp++)
  58.         ;
  59.  
  60.     if (*cp)
  61.         return -1;
  62.     else
  63.         return 0;
  64. }
  65.  
  66. /*
  67.  * change_field - change a single field if a new value is given.
  68.  *
  69.  * prompt the user with the name of the field being changed and the
  70.  * current value.
  71.  */
  72.  
  73. /* "buf" _must_ be at least BUFSIZ chars to make strcpy() safe.  --marekm */
  74.  
  75. void
  76. change_field (buf, prompt)
  77. char    *buf;
  78. char    *prompt;
  79. {
  80.     char    new[BUFSIZ];
  81.     char    *cp;
  82.  
  83.     printf ("\t%s [%s]: ", prompt, buf);
  84.     if (fgets (new, BUFSIZ, stdin) != new)
  85.         return;
  86.  
  87.     if ((cp = strchr (new, '\n')))
  88.         *cp = '\0';
  89.     else
  90.         return;
  91.  
  92.     if (new[0])
  93.         strcpy (buf, new);
  94. }
  95.